﻿using ConsoleApp2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp
{
    class Program
    {

        enum enrole
        {
            刘备 = 1,
            曹操 = 2,
            孙权 = 3
        }
        enum enMora
        {
            石头 = 1,
            剪刀 = 2,
            布 = 3
        }
        static void Main(string[] args)
        {
            Console.WriteLine("欢迎来到游戏世界" + "\n");
            Console.WriteLine("猜拳开始");
            Console.WriteLine("出拳规则：1、石头 2、剪刀 3、布");
            Console.WriteLine("请选择对方的角色（1、刘备 2 、曹操 3、孙权");
            int numname = int.Parse(Console.ReadLine());
            string npcstr = Enum.GetName(typeof(enrole), numname);
            Role role = new Role(npcstr);
            Console.WriteLine("请输入您的名字");
            string playname = Console.ReadLine();
            Console.WriteLine(playname + "Vs" + npcstr);
            Console.WriteLine("是否开始游戏（Y/N）");
            char char1 = Convert.ToChar(Console.ReadLine());
            if (char1 == 'Y' || char1 == 'y')
            {
                WinMora(role, npcstr, playname);
            }
            else if (char1 == 'N' || char1 == 'n')
            {
                Console.WriteLine("退出游戏");
            }
            Console.WriteLine("要开始新的游戏吗？（Y/N）");
            char char2 = Convert.ToChar(Console.ReadLine());
            if (char2 == 'Y' || char2 == 'y')
            {
                WinMora(role, npcstr, playname);

            }
            else if (char2 == 'N' || char2 == 'n')
            {
                Console.WriteLine("退出程序");
                System.Environment.Exit(0);
            }
        }

        private static void WinMora(Role role, string npcstr, string playname)
        {
            int draw = 0;
            int NPCwin = 0;
            int Playwin = 0;

            while (true)
            {
                Console.WriteLine("请出拳1.石头2.剪刀3.布请输入数字（请输入相应的数字）");
                int Moranum = int.Parse(Console.ReadLine());
                string playMora = Enum.GetName(typeof(enMora), Moranum); //获取用户输入的数字转化为相应的枚举里的值

                Console.WriteLine(playname + " : 出拳： " + playMora);
                role.Write();

                if (role.StrMora == playMora)
                {
                    Console.WriteLine("平局，放你一马");
                    draw = draw + 1;
                }
                else if (playMora == "石头" && role.StrMora == "剪刀" || playMora == "布" && role.StrMora == "石头" || playMora == "剪刀" && role.StrMora == "布")
                {
                    Console.WriteLine("恭喜您，勇夺三军,天下无双");
                    Playwin = Playwin + 1;
                }
                else if (role.StrMora == "剪刀" && playMora == "布" || role.StrMora == "石头" && playMora == "剪刀" || role.StrMora == "布" && playMora == "石头")
                {
                    Console.WriteLine("天啦噜,难以置信,这也会输");
                    NPCwin = NPCwin + 1;
                }
                else if (playMora != "石头" || playMora != "剪刀" || playMora != "布")
                {
                    NPCwin = NPCwin + 1;
                    Console.WriteLine("玩家，出拳不符合规则默认判负");
                }

                Console.WriteLine("是否开始下一局(y/n)");
                char char2 = Convert.ToChar(Console.ReadLine());
                if (char2 == 'y' || char2 == 'Y')
                {

                }
                else if (char2 == 'n' || char2 == 'N')
                {
                    Console.WriteLine("结束游戏");
                    Console.WriteLine("===========================");
                    Console.WriteLine(playname + " VS " + npcstr);
                    Console.WriteLine("对战次数" + (Playwin + NPCwin + draw));
                    Console.WriteLine("姓名     得分");
                    Console.WriteLine($"{playname}     {Playwin}");
                    Console.WriteLine($"{npcstr}     {NPCwin}");
                    if (Playwin > NPCwin)
                    {
                        Console.WriteLine("玩家 " + playname + " 胜出，举世同庆");
                    }
                    else if (NPCwin > Playwin)
                    {
                        Console.WriteLine("电脑" + npcstr + "胜出，棋差一手");
                    }
                    else
                    {
                        Console.WriteLine("平局");
                    }
                    break;
                }
            }
        }
    }
}
